package com.lanxum.common.utils;

import com.alibaba.fastjson.serializer.ValueFilter;

import java.text.DecimalFormat;

/**
 * @author: li.sun
 * @create: 2020-05-05 16:19
 * @description:
 **/
public class NumValueFilter implements ValueFilter {

    public static final DecimalFormat fnum = new DecimalFormat("##0.00");

    @Override
    public Object process(Object o, String propertyName, Object propertyValue) {
        if (propertyValue instanceof Float) {
            Float tp = (Float) propertyValue;
            propertyValue = new Float(fnum.format(tp));
        } else if (propertyValue instanceof Double) {
            Double td = (Double) propertyValue;
            propertyValue = new Double(fnum.format(td));
        }
        return propertyValue;
    }
}
